<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100的数字">
<input type="button" value="猜一猜" onclick="f()">
<div></div>
<script>
//得到1-100的随机数
// Math.random()*100-----0~99.9999......
let x = parseInt(Math.random()*100)+1;//0-99
let count = 0;//猜的次数
function f() {
    count++;
    let i = document.querySelector("input");
    let d = document.querySelector("dv");
    if (i.value>x){
        d.innerText = "猜大了";
    }else if (i.value<x){
        d.innerText = "猜小了";
    }else {
        d.innerText="你真是个天才,猜对了哦,一共猜了"+count+"次";
    }
}

</script>
</body>
</html>